<include file="public@header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('Office/department')}">部门管理</a></li>
			<li class="active"><a href="{:url('Office/add_department')}">添加部门</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form" action="{:url('Office/add_post')}">
			<fieldset>

                <div class="control-group">
					<label class="control-label">部门名称</label>
					<div class="controls">
						<input type="text" class="form-control"  name="department_name" required>
                        <span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">部门主管</label>
					<div class="controls">
						<select name="user_id" class="form-control" >
							<volist name="user" id="vo" >
								<option value="{$vo.id}">{$vo.user_nickname}</option>
							</volist>
						</select>
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">归属部门</label>
					<div class="controls">
						<select name="dept_type" class="form-control">
							<option value='1'>业务部</option>
							<option value="2">财务部</option>
							<option value="3">客服部</option>
							<option value="4">工程部</option>
							<option value="5">供货商</option>
							<option value="6">人事部</option>
							<option value="7">抵顶人</option>
							<option value="8">代理商</option>
							<option value="9">礼仪部</option>
							<option value="10">总经办</option>
						</select>
					</div>
				</div>
			</fieldset>
			<div class="form-actions">
				<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
				<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
    <script type="text/javascript">
	$(document).ready(function(e) {
		// 商品分类变更查询
		$("select[name='deparment_pid']").change(function(){
			var id = $(this).val();
			$(this).next().hide().find("option").not(":first").remove();
			if(id != ''){
				$.ajax({
					url		: "{:url('Admin/Department/getdepartmentAjax')}", 
					type	: "post",  
					dataType: "json", 
					data	: {'id': id, 'Ajax': 1}, 
					success : function(result){
						var html = "";
						$.each(result, function(i, n){
							html += "<option value='" + n.id + "'>" + n.department_name + "</option>";
						});
						if(html.length>0){
							$("select[name='deparment_pid']").next().show().append(html);
						}
						//$("select[name='deparment_id']").next().find("option").not(":first").remove();
					},
					error	: function(){
						alert("服务器内部错误，请联系系统管理员");
					}
				});
			}
		});
	});
	$("select[name='organize_id']").change(function(){
				var p_id = $(this).val();
				// 拼接AJAX请求
				$(this).nextAll().hide().find("option").remove();
				$.ajax({
					url		: "{:url('Admin/Organize/getParentByAjax')}", 
					type	: "post", 
					dataType: "json", 
					data	: {'id':p_id, 'Ajax': 1}, 
					success : function(result){
						$.post("{:url('Admin/Department/get_organize')}",{'id':p_id},function(result){
							//获取省分公司部门数据
							var departmenthtml="";
							departmenthtml += "<option value='0'>请选择分类</option>";
							$.each(result, function(i, n){
								departmenthtml += "<option value='" + n.id + "'>" + n.department_name + "</option>";
							});
								$("select[name='deparment_pid']").html(departmenthtml);
						},'json')
						var html="";
						html += "<option value='0'>请选择分类</option>";
						$.each(result, function(i, n){
							html += "<option value='" + n.id + "'>" + n.organize_name + "</option>";
						});
						$("select[name='organize_sub_id']").html(html);
						if(html.length>32){
							$("select[name='organize_sub_id']").show();
						}else{
							$("select[name='organize_sub_id']").hide();
						}
						
					},
					error	: function(){
						alert("服务器内部错误，请联系系统管理员");
					}
				});
			});
			$("select[name='organize_sub_id']").change(function(){
				var sub_id = $(this).val();
				var p_id=$("select[name='organize_id']").val();
				$(this).next().hide().find("option").remove();
				// 拼接AJAX请求
				$.ajax({
					url		: "{:url('Admin/Organize/getthreeByAjax')}", 
					type	: "post", 
					dataType: "json", 
					data	: {'id':p_id, 'sub_id':sub_id,'Ajax': 1}, 
					success : function(result){
						$.post("{:url('Admin/Department/get_cityorganize')}",{'id':p_id,'sub_id':sub_id},function(result){
						//h获取市级部门数据
							var departmenthtml="";
							departmenthtml += "<option value='0'>请选择分类</option>";
							$.each(result, function(i, n){
								departmenthtml += "<option value='" + n.id + "'>" + n.department_name + "</option>";
							});
								$("select[name='deparment_pid']").html(departmenthtml);
						},'json')

						var html="";
						html += "<option value='0'>请选择分类</option>";
						$.each(result, function(i, n){
							html += "<option value='" + n.id + "'>" + n.organize_name + "</option>";
						});
						$("select[name='organize_three_id']").html(html);
						if(html.length>32){
							$("select[name='organize_three_id']").show();
						}else{
							$("select[name='organize_three_id']").hide();
						}
						
					},
					error	: function(){
						alert("服务器内部错误，请联系系统管理员");
					}
				});
			});
			
			$("select[name='organize_three_id']").change(function(){
				var p_id=$("select[name='organize_id']").val();
				var sub_id=$("select[name='organize_sub_id']").val();
				var three_id = $(this).val();
				$.post("{:url('Admin/Department/get_regionorganize')}",{'id':p_id,'sub_id':sub_id,'three_id':three_id},function(result){
					//h获取县级部门数据
					var html="";
					html += "<option value='0'>请选择分类</option>";
					$.each(result, function(i, n){
						html += "<option value='" + n.id + "'>" + n.department_name + "</option>";
					});
						$("select[name='deparment_pid']").html(html);
				},'json')
			})

</script>
    
</body>
</html>